package com.jy.common;

import com.jy.controller.LoginController;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * Created by Administrator on 2017/6/1 0001.
 */
public class SendEmail {
    public static String mailServerHost="smtp.163.com";
    public static String mailServerPort="25";
    public static String username="joyijinrong@163.com";
    public static String password="joyi123";
    public static String fromAddress="joyijinrong@163.com";
    public static String content="<h2>点击下面链接激活账号，48小时生效，否则重新注册账号，链接只能使用一次，请尽快激活！<h2>";
    //public static String href="http://localhost:8080/weixin/login/";
    public static String href="http://120.27.27.109/weixin/login/";
    //public static String href="http://120.27.27.109:8085/finance/member.do?method=Validate";

    public  SendEmail(){
        Properties prop =  new  Properties();
        InputStream ins =LoginController.class.getResourceAsStream("/mail.properties");
        try {
            prop.load(ins);
        } catch (IOException e2) {
            // TODO Auto-generated catch block
            e2.printStackTrace();
        }
        mailServerHost=prop.getProperty("mailServerHost");
        mailServerPort=prop.getProperty("mailServerPort");
        username=prop.getProperty("username");
        password=prop.getProperty("password");
        fromAddress=prop.getProperty("fromAddress");
        content=prop.getProperty("content");
        href=prop.getProperty("href");
    }
    public static void send(String toAddress,String code,String method){
        // 这个类主要是设置邮件
        MailSenderInfo mailInfo = new MailSenderInfo();
        mailInfo.setMailServerHost(mailServerHost);
        mailInfo.setMailServerPort(mailServerPort);
        mailInfo.setValidate(true);
        mailInfo.setUserName(username); // 实际发送者
        mailInfo.setPassword(password);// 您的邮箱授权码密码
        mailInfo.setFromAddress(fromAddress); // 设置发送人邮箱地址
        mailInfo.setToAddress(toAddress); // 设置接受者邮箱地址
        mailInfo.setSubject("账号激活");
        mailInfo.setContent(content+"<h3><a href='"+href+method+"?code="+code+"&mail="+toAddress+"'>"+href+"</a></h3>");
        // 这个类主要来发送邮件
        SimpleMailSender sms = new SimpleMailSender();
        sms.sendHtmlMail(mailInfo); // 发送文体格式
        //sms.sendHtmlMail(mailInfo); // 发送html格式
    }


}
